package org.zsk.cs.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.zsk.cs.domain.po.HotVideo;
import org.zsk.cs.domain.vo.HotVideoVo;
import org.zsk.cs.response.ResultBody;
import org.zsk.cs.service.UploadService;
import org.zsk.cs.util.UserUtils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
 * <p>
 *     上传文件 controller
 * </p>
 *
 * @author zsk
 * @version 1.0
 * Created on 2020/4/13
 */
@RestController
@RequestMapping("/upload")
@Slf4j
public class UploadController {

    private final UploadService uploadService;

    @Autowired
    public UploadController(UploadService uploadService) {
        this.uploadService = uploadService;
    }

    @PostMapping("/avatar")
    public ResultBody uploadAvatar(@RequestParam("file") MultipartFile file) {
        return ResultBody.success(uploadService.uploadAvatar(file));
    }

    @PostMapping("/hotvideo")
    public ResultBody uploadHotVideo(HotVideoVo hotVideoVo) throws Exception {
        return ResultBody.success(uploadService.uploadHotVideo(hotVideoVo));
    }

    @PostMapping("/upload")
    public ResultBody upload(String param1, String param2, @RequestParam("myFile")MultipartFile myFile) {
        System.out.println("--- 接收文件 ---");
        System.out.println("param1：" + param1);
        System.out.println("param2：" + param2);
        String originalFilename = myFile.getOriginalFilename();
        System.out.println("文件原始名称：" + originalFilename);
        // 处理文件内容...
        return ResultBody.success();
    }
}
